package com.example.springframeworklearning.validator;

import com.example.springframeworklearning.domain.OrderItem;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

/**
 * 订单项校验器
 *
 * @author luo
 * @since 2022/9/21 17:15
 */
@Component
public class OrderItemValidator implements Validator {
    @Override
    public boolean supports(Class<?> clazz) {
        return OrderItem.class.equals(clazz);
    }

    @Override
    public void validate(Object target, Errors errors) {

        ValidationUtils.rejectIfEmpty(errors, "name", "订单项的名称不能为空");
    }
}
